<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../css/layui.css" media="all">
</head>
<body style="padding-left: 20px;">
<br/>
<form class="layui-form" id="form-add" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="nickName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="text" name="pwd" lay-affix="eye" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单选框</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男" checked>
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="text" name="tel" lay-verify="required|phone" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" lay-verify="email" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" id="add_btn" lay-submit lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<br/>

</body>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/layui.js" charset="utf-8"></script>
<script>
    layui.use(['layer', 'form'], function(){
        var layer = layui.layer,
            form = layui.form;
        //监听提交
        form.on('submit(demo1)', function(data){

            console.log("nickName:"+data.field.nickName);

            $.ajax({
                url: '../../admin?op=add',
                type: "POST",
                data: {
                    nickName: data.field.nickName,
                    pwd: data.field.pwd,
                    sex:data.field.sex,
                    tel:data.field.tel,
                    email:data.field.email,
                    state:data.field.state
                },
                success: function (msg) {
                    console.log(msg)
                    if (msg == "1") {
                        layer.msg('添加成功!',function() {time:2000})
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        window.parent.location.reload();   //刷新父界面
                        parent.layer.close(index);
                    } else if (msg=="2"){
                        layer.msg("添加失败,你的权限不足，请联系超级管理员", function() {time:2000});
                    }else {
                        layer.msg("添加失败");
                    }
                }
            });
            return false;

        });
    });

</script>
</html>